package cn.liit.weixin.core.basic.accesstoken;

import java.util.Date;

/**
 * 存放access_token信息
 * access_token是公众号的全局唯一票据，公众号调用各接口时都需使用access_token。
 * 开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间。
 * access_token的有效期目前为2个小时，需定时刷新，重复获取将导致上次获取的access_token失效。
 * @author boqi.zhang
 */
public class AccessToken {
	private String access_token;//获取到的凭证
	private Integer expires_in;//凭证有效时间，单位：秒
	private boolean isloaded;//用来标记凭证是否已经加载
	private Date expires_date;//到期时间
	private volatile static AccessToken instance;//实例
	
	public String getAccess_token() {
		return access_token;
	}
	public void setAccess_token(String access_token) {
		this.access_token = access_token;
	}
	public Integer getExpires_in() {
		return expires_in;
	}
	public void setExpires_in(Integer expires_in) {
		this.expires_in = expires_in;
	}
	public boolean isIsloaded() {
		return isloaded;
	}
	public void setIsloaded(boolean isloaded) {
		this.isloaded = isloaded;
	}
	
	private AccessToken() {
		super();
	}
	
	public Date getExpires_date() {
		return expires_date;
	}
	
	public void setExpires_date(Date expires_date) {
		this.expires_date = expires_date;
	}
	
	public static AccessToken getInstance(){
		if(instance == null){
			synchronized (AccessToken.class) {
				instance = new AccessToken();
			}
		}
		return instance;
	}
	
	@Override
	public String toString() {
		return "AccessToken [access_token=" + access_token + ", expires_in="
				+ expires_in + "]";
	}
	
}
